cc.Class({
  extends: cc.Component,

  properties: {
    target: {
      default: null,
      type: cc.Node
    }
  },

  // LIFE-CYCLE CALLBACKS:

  onLoad() {
    this.camera = this.getComponent(cc.Camera);
    this.isdie = false;

    this.node.position.y = cc.winSize.height * 0.5;

    this.start = false;
  },

  start() {

  },

  onEnable: function () {
    cc.director.getPhysicsManager().attachDebugDrawToCamera(this.camera);
  },
  onDisable: function () {
    cc.director.getPhysicsManager().detachDebugDrawFromCamera(this.camera);
  },

  // update (dt) {},

  lateUpdate: function (dt) {


    let targetPos = this.target.convertToWorldSpaceAR(cc.Vec2.ZERO);
    let pos = this.node.parent.convertToNodeSpaceAR(targetPos);
    let y = pos.y;
    // cc.log("y ============================== "+y);
    // cc.log("y =========this.node.position.y===================== "+this.node.position.y);
    if ((Math.floor(y) > Math.floor(this.node.position.y))) {
      this.start = true;
    }
    if (this.start && !this.isdie) {
      // if(this.isdie && this.node.position.y <  cc.winSize.height*0.5){
      //     this.node.position.y = cc.winSize.height*0.5;
      // }
      if ((Math.floor(y) > Math.floor(this.node.position.y))) {
        this.node.position = cc.v2(0, y);
      }

      // cc.log("y ==============================1111111 ");
    } else if (this.isdie) {
      if (this.node.position.y < cc.winSize.height * 0.5) {
        this.node.position.y = cc.winSize.height * 0.5;
      }
      // if((Math.floor(y) > Math.floor(this.node.position.y))){
      this.node.position = cc.v2(0, y + cc.winSize.height * 0.45);
      // }
    }

    if ((Math.floor(this.node.position.y) - Math.floor(pos.y)) > cc.winSize.height * 0.5) {
      window.Game.player.getComponent("Player").die();
      this.isdie = true;
    }


  }

});
